from pydantic import BaseModel, field_validator
import re
from decimal import Decimal

class CustomerIn(BaseModel):
    name: str
    address: str
    phoneNumber: str
    presenter : str

    @field_validator('phoneNumber')
    def must_be_phone_number(phoneNumber):  # Use cls instead of no argument to follow Pydantic's conventions
        chinese_phone_pattern = re.compile(r'^1[3-9]\d{9}$')  # Regular expression for Chinese phone numbers
        if not chinese_phone_pattern.match(phoneNumber):
            raise ValueError("Invalid Chinese phone number format")
        return phoneNumber


class KumquatIn(BaseModel):
    name: str
    style: str
    original_price: Decimal
    price: Decimal
    # profit: Decimal = 0
    note: str = 'CURRENT'


class UserIn(BaseModel):
    name: str
    email: str = "example@qq.com"
    phoneNumber: str = "None"
    password_hashed: str
    role: str = "MANAGER"


class OrderIn(BaseModel):
    customer_name: str
    customer_addr: str
    customer_presenter: str = 'ME'
    customer_phoneNumber: str
    kumquat_name: str
    kumquat_style: Decimal
    quantity: int
    on_sold: Decimal = 1
    # price: Decimal = 0
    status: str = '已下单'
    order_delivery_code: str = 'None'
    book_date: str
    note: str = ''

class OrderFilter(BaseModel):
    customer_name: str = ''
    customer_presenter: str = ''
    kumquat_name: str = ''
    kumquat_style: str = ''
    start_date: str = ''
    end_date: str = ''
    status: str = ''
    note: str = ''


# import unittest
#
# class TestCustomer(unittest.TestCase):
#
#     def test_phone_number_validation(self):
#         # Test with a valid phone number
#         valid_customer = Customer(name="John Doe", address="123 Main St", phoneNumber="13812345678")
#         self.assertEqual(valid_customer.presenter, "None")  # Ensure default value works
#         self.assertEqual(valid_customer.phoneNumber, "13812345678")  # Ensure the number is set correctly
#
#         # Test with an invalid phone number
#         with self.assertRaises(ValueError):
#             invalid_customer = Customer(name="Jane Doe", address="456 Elm St", phoneNumber="12345678901")
#
# if __name__ == '__main__':
#     unittest.main()
